{% extends "profiles/base_profile_edit.html" %}

{% load i18n %}
{% load pagination_tags %}

{% block title %}{% trans "Security Log" %}{% endblock %}

{% block profile-admin-security-log %}active{% endblock %}

{% block edit_content_header %} {% trans "Security Log" %} {% endblock %}

{% block edit_content %}

<p>
  {% blocktrans trimmed with days_limit as days_limit %}
  Showing logs from the last {{ days_limit }} days.
  {% endblocktrans %}
</p>

{% autopaginate object_list 15 %}

<div class="module">
  <form method="get">
    <button type="submit" name="download" value="true">{% trans "Download all data" %}</button>
  </form>

  <div class="module-list">
    <div class="module-list-wrapper">
      <ul>
        {% for log in object_list %}
        <li class="module-item">
          {% if log.action == AuditLog.AUTHN %}
            {% blocktrans trimmed with action=AuditLog.AUTHN%}
            <a href="?action={{ action }}">Authenticated</a>
            {% endblocktrans %}
          {% elif log.action == AuditLog.AUTHN_FAILURE %}
            {% blocktrans trimmed with action=AuditLog.AUTHN_FAILURE %}
            <a href="?action={{ action }}">Authentication attempt</a>
            {% endblocktrans %}
          {% endif %}

          {% trans "from" %}

          <a href="?ip={{ log.ip }}" title="{{ log.browser }}">
            <code>{{ log.ip }}</code>
          </a>

          {# If the authentication was on a doc domain. #}
          {% if log.log_project_id %}
            {% trans "on" %}
            {% if log.project %}
              <a href="{% url 'projects_detail' log.log_project_slug %}">
                <code>{{ log.log_project_slug }}</code>
              </a>
            {% else %}
              {# The original project has been deleted, don't link to it. #}
              <code>{{ log.log_project_slug }}</code>
            {% endif %}
          {% endif %}

          <span class="quiet right" title="{{ log.created|date:"DATETIME_FORMAT" }}">
            {% blocktrans trimmed with log.created|timesince as date %}
            {{ date }} ago
            {% endblocktrans %}
          </span>
        </li>
        {% empty %}
        <li class="module-item">
          <p class="quiet">
          {% trans 'No authentication attempts logged yet' %}
          </p>
        </li>
        {% endfor %}
      </ul>
    </div>
  </div>
</div>
{% paginate %}
{% endblock %}
